@charset "UTF-8";

// Built-in modules
@use "sass:color";
@use "sass:list";
@use "sass:map";
@use "sass:math";
@use "sass:meta";
@use "sass:selector";
@use "sass:string";

// Mixkit settings and modules
@use "mixkit/settings" as settings;
@use "define" as shorthand;

/// Builds directional CSS declarations using shorthand.
///
/// @name directional
///
/// @group mixkit/shorthand
///
/// @param {string} $property
///   A CSS property.
///
/// @param {string} $suffix
///   A CSS suffix. Use `null` to ignore.
///
/// @param {list (with units)} $shorthand
///   List of valid CSS lengths ranging from 1-4.
///
/// @require {function (mixkit/shorthand)} define
///
/// @output CSS declarations.
///
/// @access public
///
/// @since 1.0.0

@mixin directional($property, $suffix, $shorthand) {
  $length: list.length($shorthand);
  $null: meta.type-of(list.index($shorthand, null)) == "number";
  $map: shorthand.define(map, $shorthand);
  $top: $property + "-top" + if($suffix, "-#{$suffix}", "");
  $right: $property + "-right" + if($suffix, "-#{$suffix}", "");
  $bottom: $property + "-bottom" + if($suffix, "-#{$suffix}", "");
  $left: $property + "-left" + if($suffix, "-#{$suffix}", "");

  // Type checks
  @if not
    meta.type-of($property) == "string" or not
    meta.type-of($suffix) == "string" or not
    meta.type-of($shorthand) == "string" or not
    meta.type-of($shorthand) == "number" or not
    meta.type-of($shorthand) == "list" {
    @error "Invalid argument type/s.";
  }

  @for $i from 1 through 4 {
    @if $i == 1 and map.get($map, $i) != null {
      #{$top}: map.get($map, 1);
    } @else if $i == 2 and map.get($map, $i) != null {
      #{$right}: map.get($map, 2);
    } @else if $i == 3 and map.get($map, $i) != null {
      #{$bottom}: map.get($map, 3);
    } @else if $i == 4 and map.get($map, $i) != null {
      #{$left}: map.get($map, 4);
    }
  }
}
